package com.plm.mqshequ.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 正则表达式工具
 * @author Limi
 * @create 2019-01-17 19:01
 */
public class RegexUtils {

    // 手机正则表达式
    private static String phoneRegx = "^[1](([3][0-9])|([4][5,6,7,8,9])|([5][^4,6,9])|([6][6])|([7][3,4,5,6,7,8])|([8][0-9])|([9][8,9]))[0-9]{8}$";
    // 邮箱正则表达式
    private static String emailRegx = "^\\w+((-\\w+)|(\\.\\w+))*\\@[A-Za-z0-9]+((\\.|-)[A-Za-z0-9]+)*\\.[A-Za-z0-9]+$";

    /**
     * 手机合法性验证
     */
    public static boolean verifyPhone (String phone) {
        Pattern pattern = Pattern.compile(phoneRegx);
        Matcher matcher = pattern.matcher(phone);
        return matcher.matches();
    }

    /**
     * 邮箱合法性验证
     */
    public static boolean verifyEmail (String email) {
        Pattern pattern = Pattern.compile(emailRegx);
        Matcher matcher = pattern.matcher(email);
        return matcher.matches();
    }
}
